import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { AppService } from './app.service';
import { CreateDeviceDto } from './Dtos/CreateDevice.dto';
import { PageInfo } from './Dtos/PageInfo.dto';
import { Device } from './Entities/device.entity';
import { ResData } from './Types/ResData';

@Controller('sets')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  async getDevice(@Query() pageInfo: PageInfo): Promise<ResData<Device []>> {
    const data = await this.appService.getDevice(pageInfo);
    return {
      errmsg: '',
      errno: 200,
      data,
    }
  }

  @Post()
  async createDevice(@Body() device: CreateDeviceDto): Promise<ResData<Device>> {
    const data = await this.appService.createDevice(device);
    return {
      errmsg: '',
      errno: 200,
      data, // 这里为什么不是 id: 3，因为没有意义，要么不返回任何数据相关，直接返回 201，要么将数据都返回。如果想获得指定字段的值，使用 GraphQL
    };
  }
}
